// Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import 'package:pigeon/pigeon.dart';

@ConfigurePigeon(PigeonOptions(
  dartOut: 'lib/src/messages.g.dart',
  dartOptions: DartOptions(),
  dartTestOut: 'test/test_api.g.dart',
  dartPackageName: 'image_picker_ohos',
))

enum SourceCamera {
  rear,
  front,
}

enum SourceType {
  camera,
  gallery,
}

enum CacheRetrievalType {
  image,
  video,
}

class GeneralOptions {
  GeneralOptions({
    required this.allowMultiple,
    required this.usePhotoPicker,
    this.maxSelectCount = 10,
  });

  bool allowMultiple;
  bool usePhotoPicker;
  int maxSelectCount;
}

class ImageSelectionOptions {
  ImageSelectionOptions({
    this.maxWidth,
    this.maxHeight,
    required this.quality,
  });

  double? maxWidth;
  double? maxHeight;
  int quality;
}

class MediaSelectionOptions {
  MediaSelectionOptions({
    required this.imageSelectionOptions,
  });

  ImageSelectionOptions imageSelectionOptions;
}

class VideoSelectionOptions {
  VideoSelectionOptions({
    this.maxDurationSeconds,
  });

  int? maxDurationSeconds;
}

class SourceSpecification {
  SourceSpecification({
    required this.type,
    this.camera,
  });

  SourceType type;
  SourceCamera? camera;
}

class CacheRetrievalError {
  CacheRetrievalError({
    required this.code,
    this.message,
  });

  String code;
  String? message;
}

class CacheRetrievalResult {
  CacheRetrievalResult({
    required this.type,
    this.error,
    required this.paths,
  });

  CacheRetrievalType type;
  CacheRetrievalError? error;
  List<String?> paths;
}

@HostApi()
abstract class ImagePickerApi {
  List<String?> pickImages(
    SourceSpecification source,
    ImageSelectionOptions options,
    GeneralOptions generalOptions,
  );

  List<String?> pickVideos(
    SourceSpecification source,
    VideoSelectionOptions options,
    GeneralOptions generalOptions,
  );

  List<String?> pickMedia(
    MediaSelectionOptions mediaSelectionOptions,
    GeneralOptions generalOptions,
  );

  CacheRetrievalResult? retrieveLostResults();
}
